/*********************************************************************************/
/*                                                                               */
/*      GPT Driver                                                               */
/*                                                                               */
/*      Last updated by:   CBS                                                   */
/*      Last update date:  2013/1/25                                             */
/*      Revision:          0                                                     */
/*      Copyright:         DENS0                                                 */
/*                                                                               */
/*********************************************************************************/

#ifndef GPT_H
#define GPT_H

/*********************************************************************************/
/*  include files                                                                */
/*********************************************************************************/
#include "Std_Types.h"
#include "Gpt_Cfg.h"

/*********************************************************************************/
/*  defines / data types / structs / unions / macros                             */
/*********************************************************************************/
/* Std PIT channels */
#define GPT_CHANNEL_RTI       0
#define GPT_CHANNEL_PIT_1	  1
#define GPT_CHANNEL_PIT_2     2
#define GPT_CHANNEL_PIT_3     3
#define GPT_CHANNEL_PIT_4     4

#define GPT_PIT_CNT           4

#define GPT_CHANNEL_CNT	      5

/* Illegal channel */
#define GPT_CHANNEL_ILL       31

/* ISR Priority */
#define ISR_Priority_1        0
#define ISR_Priority_2        1
#define ISR_Priority_3        2
#define ISR_Priority_4        3
#define ISR_Priority_5        4
#define ISR_Priority_6        5
#define ISR_Priority_7        6
#define ISR_Priority_8        7
#define ISR_Priority_9        8
#define ISR_Priority_10       9
#define ISR_Priority_11       10
#define ISR_Priority_12       11
#define ISR_Priority_13       12
#define ISR_Priority_14       13
#define ISR_Priority_15       14
#define ISR_Priority_16       15


/* Time channel state */
typedef enum
{
  GPT_STATE_STOPPED = 0,
  GPT_STATE_STARTED,
} Gpt_StateType;

/* Pre-compile only */
#define GPT_VARIANT_PC	                        STD_OFF
/* Mix of pre-compile and post-build */
#define GPT_VARIANT_PB                          STD_ON

#define GPT_DEV_ERROR_DETECT                    STD_ON
#define GPT_REPORT_WAKEUP_SOURCE                STD_OFF
#define GPT_DEINIT_API							STD_ON
#define GPT_ENABLE_DISABLE_NOTIFICATION_API	    STD_ON
#define GPT_TIME_REMAINING_API					STD_ON
#define GPT_TIME_ELAPSED_API                    STD_ON
#define GPT_VERSION_INFO_API					STD_ON
#define GPT_WAKEUP_FUNCTIONALITY_API			STD_OFF

/* Error Codes */
#define GPT_E_UNINIT                            0x0a
#define GPT_E_BUSY 				                0x0b
#define GPT_E_NOT_STARTED 			            0x0c
#define GPT_E_ALREADY_INITIALIZED               0x0d
#define GPT_E_PARAM_CHANNEL                     0x14
#define GPT_E_PARAM_VALUE 			            0x15
#define GPT_E_PARAM_MODE 			            0x1f
#define GPT_E_PARAM_CONFIG                      0x0e

/* Service IDs */
#define GPT_INIT_SERVICE_ID                     0x01
#define GPT_DEINIT_SERVICE_ID                   0x02
#define GPT_GETTIMEELAPSED_SERVICE_ID           0x03
#define GPT_GETTIMEREMAINING_SERVICE_ID         0x04
#define GPT_STARTTIMER_SERVICE_ID               0x05
#define GPT_STOPTIMER_SERVICE_ID                0x06
#define GPT_ENABLENOTIFICATION_SERVICE_ID       0x07
#define GPT_DISABLENOTIFICATION_SERVICE_ID      0x08
#define GPT_SETMODE_SERVIVCE_ID                 0x09
#define GPT_DISABLEWAKEUP_SERVICE_ID            0x0a
#define GPT_ENABLEWAKEUP_SERVICE_ID             0x0b
#define GPT_CBK_CHECKWAKEUP_SERVICE_ID          0x0c



#define GPT_VENDOR_ID             (U2)1
#define GPT_MODULE_ID             (U2)1
#define GPT_INSTANCE_ID	          (U2)0

#define GPT_SW_MAJOR_VERSION      (U1)1
#define GPT_SW_MINOR_VERSION   	  (U1)0
#define GPT_SW_PATCH_VERSION      (U1)1

#define GPT_AR_MAJOR_VERSION      (U1)2
#define GPT_AR_MINOR_VERSION      (U1)2
#define GPT_AR_PATCH_VERSION      (U1)1

#define INTC_PIT1_VectorNum       301
#define INTC_PIT2_VectorNum       302
#define INTC_PIT3_VectorNum       303
#define INTC_PIT4_VectorNum       304
#define INTC_RTI_VectorNum        305



/*********************************************************************************/
/*  API Functions                                                                */
/*********************************************************************************/

/************************************************************************************************************************/
/*  Service name        :   Gpt_Init                                                                                    */
/*  Sync/Async          :   Synchronous                                                                                 */
/*  Reentrancy          :   Non Reentrant                                                                               */
/*  Parameters (in)     :   Pointer to a selected configuration structure                                               */
/*  Return value        :   None                                                                                        */
/*  Discription         :   Initializes the hardware timer module                                                       */
/************************************************************************************************************************/
void Gpt_Init(const Gpt_ConfigType *ConfigPtr);

/************************************************************************************************************************/
/*  Service name        :   Gpt_DeInit                                                                                  */
/*  Sync/Async          :   Synchronous                                                                                 */
/*  Reentrancy          :   Non Reentrant                                                                               */
/*  Parameters (in)     :   None                                                                                        */
/*  Return value        :   None                                                                                        */
/*  Discription         :   Deinitializes all hardware timer channels                                                   */
/************************************************************************************************************************/
void Gpt_DeInit(void);

/************************************************************************************************************************/
/*  Service name        :   Gpt_StartTimer                                                                              */
/*  Sync/Async          :   Synchronous                                                                                 */
/*  Reentrancy          :   Non Reentrant                                                                               */
/*  Parameters (in)     :   Channel    Numeric identifier of the GPT channel                                            */
/*                          Value      Target time in number of ticks                                                   */
/*  Return value        :   None                                                                                        */
/*  Discription         :   Starts a timer channel                                                                      */
/************************************************************************************************************************/
void Gpt_StartTimer(Gpt_ChannelType channel, Gpt_ValueType period_ticks);

/************************************************************************************************************************/
/*  Service name        :   Gpt_StopTimer                                                                               */
/*  Sync/Async          :   Synchronous                                                                                 */
/*  Reentrancy          :   Non Reentrant                                                                               */
/*  Parameters (in)     :   Channel    Numeric identifier of the GPT channel                                            */
/*  Return value        :   None                                                                                        */
/*  Discription         :   Stops a timer channel                                                                       */
/************************************************************************************************************************/
void Gpt_StopTimer(Gpt_ChannelType channel);

/************************************************************************************************************************/
/*  Service name        :   Gpt_GetTimeRemaining                                                                        */
/*  Sync/Async          :   Synchronous                                                                                 */
/*  Reentrancy          :   Non Reentrant                                                                               */
/*  Parameters (in)     :   Channel    Numeric identifier of the GPT channel                                            */
/*  Return value        :   Gpt_ValueType     Remaining timer value (in number of ticks)                                */
/*  Discription         :   Returns the time remaining until the target time is reached                                 */
/************************************************************************************************************************/
Gpt_ValueType Gpt_GetTimeRemaining(Gpt_ChannelType channel);

/************************************************************************************************************************/
/*  Service name        :   Gpt_GetTimeElapsed                                                                          */
/*  Sync/Async          :   Synchronous                                                                                 */
/*  Reentrancy          :   Non Reentrant                                                                               */
/*  Parameters (in)     :   Channel    Numeric identifier of the GPT channel                                            */
/*  Return value        :   Gpt_ValueType     Elapsed timer value (in number of ticks)                                  */
/*  Discription         :   Returns the time already elapsed                                                            */
/************************************************************************************************************************/
Gpt_ValueType Gpt_GetTimeElapsed(Gpt_ChannelType channel);

/************************************************************************************************************************/
/*	Service name        :	Gpt_GetVersionInfo                                                                          */
/*	Sync/Async          :	Synchronous                                                                                 */
/*	Reentrancy          :	Reentrant                                                                                   */
/*	Parameters (out)    :	VersionInfoPtr 	    Pointer to where to store the version information of this module.	    */
/*	Return value        :   None                                                                                        */
/*	Description	        : 	Returns the version information of this module.                                             */
/************************************************************************************************************************/
void Gpt_GetVersionInfoPtr(Std_VersionInfoType* VersionInfoPtr);





#endif/* GPT_H */

/**** End Of File ****************************************************************/
